/*
 * @Author: 李石
 * @Date: 2024-05-18 21:00:19
 * @LastEditors: lishi
 * @LastEditTime: 2024-05-21 18:34:21
 * @Description: 
 * Copyright (c) 2024 by ${lishi0105@163.com}, All Rights Reserved. 
 */
#ifndef _HTTP_DATA_HANDLER_HPP_
#define _HTTP_DATA_HANDLER_HPP_

#include <iostream>
#include <memory>
#include <map>
#include "BaseDto.hpp"
#include "StreamService.hpp"

class HttpDataHandler {
public:
    using Ptr = std::shared_ptr<HttpDataHandler>;
    void init();
    static Ptr CreateShared(){ return std::make_shared<HttpDataHandler>(); }
    HttpDataHandler();
    ~HttpDataHandler() = default;

    void HandleAddStreamProxy(struct mg_connection* connection, struct mg_http_message* hm);
    void HandleGetStreamList(struct mg_connection* connection, struct mg_http_message* hm);
    void HandleGetStreamInfo(struct mg_connection* connection, struct mg_http_message* hm);
    void HandleDeleteStreamProxy(struct mg_connection* connection, struct mg_http_message* hm);
    void HandleNotFound(struct mg_connection* connection, struct mg_http_message* hm);

private:
    template<typename DtoType>
    void response_handler(struct mg_connection* connection, int code, std::shared_ptr<DtoType> dto);
    std::map<int, std::string> errno_map_;
    StreamService::Ptr stream_service;
};

#endif // _HTTP_DATA_HANDLER_HPP_